package org.lionsoul.websnail.downloader;

import org.lionsoul.websnail.downloader.http.HttpClientDownloader;
import org.lionsoul.websnail.downloader.webdriver.DefaultWebDriverBuilder;
import org.lionsoul.websnail.downloader.webdriver.WebDriverBuilder;
import org.lionsoul.websnail.downloader.webdriver.WebDriverDownloader;
import org.openqa.selenium.chrome.ChromeOptions;

/**
 * @author yangjian
 */
public class DownloaderFactory {

  public static Downloader getDownloader(String type, Proxy proxy) {
    if (Downloader.WEB_DRIVER.equals(type)) {
      ChromeOptions options = new ChromeOptions();
      options.addArguments("--headless"); // 默认开启无头模式
      WebDriverBuilder builder = new DefaultWebDriverBuilder(1, options, proxy);
      return new WebDriverDownloader(builder);
    }
    return new HttpClientDownloader(proxy);
  }
}
